<template>
    <section>
        <el-col :span="24" class="toolbar">
            <el-form :inline="true">
                <el-form-item>
                    <el-input placeholder="请输入课程名或教师名" v-model="searchData" clearable/>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" @click="search">查询</el-button>
                </el-form-item>
            </el-form>
        </el-col>

        <el-table :data="courseTeacherList" border highlight-current-row style="width: 100%">
            <el-table-column type="index" width="50"></el-table-column>
            <el-table-column prop="course.name" label="课程名称" min-width="250"></el-table-column>
            <el-table-column prop="teachDetail.user.realname" label="授课教师" min-width="250"></el-table-column>
            <el-table-column prop="courseTeacher.nickname" label="教学班别称" min-width="250"></el-table-column>
            <el-table-column label="操作" min-width="350">
                <template slot-scope="scope">
                    <el-button size="mini" @click="GoCourse(scope.row.course.id,scope.row.course.name)">进入课程</el-button>
                </template>
            </el-table-column>
        </el-table>
    </section>
</template>

<script>
    export default {
        name: "courses",
        data(){
            return {
                courseTeacherList:[],
                studentInfo:{},
                currentUser:{},
                searchData:""
            }
        },
        methods:{
            getUserInfo(){
                this.user = JSON.parse(localStorage.getItem("CurrentUser"));
                this.$http.get("/api/studentinfo/findByUserid/"+this.user.id).then((res)=>{
                    this.studentInfo = res.data.data;
                    this.getDataList();
                }).catch((error)=>{
                    console.log(error);
                });
            },
            getDataList(){
                let para = {
                    studentid:this.studentInfo.id,
                    keyword:this.searchData
                };
                this.$http.post("/api/coursestudent/findCoursesByCondition",para).then((res)=>{
                    console.log(res.data.data);
                    this.courseTeacherList = res.data.data;
                }).catch((error)=>{
                    console.log(error);
                });
            },
            GoCourse(num,name){
                this.$router.push({
                    path:'/stuCourseDetail',query:{courseid:num,coursename:name}});
            },
            search(){
                this.getDataList();
            }

        },
        mounted(){
            this.getUserInfo();
        }
    }
</script>

<style scoped>

</style>
